<template>
    <div class="container">
        <div class="bg">
            <!-- 头部tabs的地方 -->
            <div class="topHead">
                <div class="left">
                    <h6 class="con">书架</h6>
                </div>

                <div class="right">
                    <i></i>
                    <i></i>
                </div>
            </div>


            <!-- 书架 -->
            <div class="book">
                <div class="title">
                    <h6><i></i> 图书配套 ({{much}})</h6>
                    <h6 v-if="!boos" @click="bianji">编辑</h6>
                    <h6 v-if="boos" @click="bianji" style="color:red;">退出编辑</h6>
                </div>

                <div class="listss">
                    <div  class="add1" v-for="item in list" :key="item">
                        <i :class="(boos == true?'con':'')" @click="del(item.key)"></i>
                        <div class="imgs" @click="govideo(item)"><img :src="item.img" alt=""></div>
                        <div class="titles22">{{ item.title }}</div>
                    </div>

                    <div class="add" @click="libraries">
                    </div>
                </div>
            </div>

            <div>
                <div class="tuijian"></div>
                <div class="list">
                    <div class="show">
                        <div class="nohave">
                            <img src="../assets/img/icon_empty_work.png" alt="" />
                            <h6>暂无网课哦~</h6>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <bottomNav />
    </div>
</template>
<script>
import bottomNav from "@/components/bottomNav.vue"
import router from '@/router'
import { onMounted, reactive, ref, toRefs } from 'vue'
export default {
    components: { bottomNav },
    setup() {
        let boos = ref(false)
        let data = reactive({
            list: null,
            much:0
        })
        let libraries = () => {
            router.push({
                path: "/libraries"
            })
        }

        let bianji = () => {
            boos.value = !boos.value
        }

        //点击删除
        let del = (key)=>{
            console.log(data.list.findIndex(item=>item.key == key));
            let aa= data.list.findIndex(item=>item.key == key)
            if(aa != -1){
                data.list.splice(aa,1)
                window.localStorage.setItem("losg",JSON.stringify(data.list))
            }
            data.much = data.list.length
        }

        let govideo = (item)=>{
            window.localStorage.setItem("datas",JSON.stringify(item))
            router.push({
                path:"/video"
            })
        }

        //获取数据
        onMounted(() => {
            data.list = JSON.parse(window.localStorage.getItem("losg"))
            console.log(data.list);
            if(data.list){

                data.much = data.list.length
            }
        })

        return {
            libraries,
            ...toRefs(data),
            boos,
            bianji,
            del,
            govideo
        }
    },
}

</script>

<style lang="scss" scoped>
@import "../assets/css/base.css";

.bg {
    padding: 0px 15px;
    height: 100%;
    background-image: linear-gradient(#ffffff, #f1f1f8);

    .tuijian {
        margin-top: 38px;
        height: 60px;
        background: url(../assets/img/study_re.png) no-repeat center center;
        background-size: 60%;
    }

    .list {
        padding: 0px 14px;
        background-color: #fff;
        height: 450px;
        border-radius: 5px;
        box-shadow: 0px 0px 8px #f1f1f8;
    }
}


.container .bg .topHead {
    display: flex;
    justify-content: space-between;
    padding-top: 20px;
    height: 52px;
    align-items: center;

    .left {
        display: flex;
        color: #979797;

        h6 {
            height: 52px;
            line-height: 52px;
            font-size: 16px;
            margin: 0px 9px;

            &.con {
                color: #000000;
                font-size: 21px;
                font-weight: bold;
            }
        }
    }

    .right {
        display: flex;

        i:nth-child(1) {
            display: block;
            background-image: url(../assets/img/icon_scan_home.png);
            width: 25px;
            height: 25px;
            background-size: 25px 25px;
            margin-right: 24px;
        }

        i:nth-child(2) {
            display: block;
            background-image: url(../assets/img/icon_msg.png);
            width: 25px;
            height: 25px;
            background-size: 25px 25px;
            margin-right: 6px;
        }
    }
}

.bg .search {
    margin-top: 12px;
    background-color: #fafbfd;
    display: flex;
    height: 38px;
    align-items: center;
    border-radius: 5px;
    box-shadow: 0px 5px 8px 0px #f3f3f3;

    input {
        flex: 1;
        height: 38px;
        background-color: #fafbfd;
        padding-left: 15px;
    }

    h6 {
        padding: 0px 20px;
        border-left: 1px solid #f0f1f3;
        font-weight: bold;
        color: #161719;
    }
}

.title {
    display: flex;
    justify-content: space-between;
    margin-top: 27px;

    h6:nth-child(1) {
        font-size: 18px;
        font-weight: bold;
        display: flex;
        align-items: center;

        i {
            width: 17px;
            height: 17px;
            display: block;
            background: url(../assets/img/083bfd5285665a447bc0c0ee09a1a01.png) no-repeat;
            background-size: 17px 17px;
            padding-right: 5px;
        }
    }

    h6:nth-child(2) {
        font-size: 12px;
        color: #adacb6;
    }
}

.show {
    .nohave {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        img {
            margin-top: 60px;
            width: 150px;
            opacity: 0.2;
        }

        h6 {
            font-size: 21px;
            color: #e3e3e3;
            margin-top: 20px;
        }
    }
}

.add {
    width: 97px;
    height: 126px;
    border-radius: 10px;
    box-shadow: 0px 0px 8px #f1f1f5;
    margin: 0px 5px;
    background: url(../assets/img/6f777c8b3744ff02ab086bc05dbea6b.png) no-repeat center center;
    background-size: 20%;
    background-color: #ffffff;
}

.listss {
    display: flex;
    flex-wrap: wrap;
    margin-top: 20px;
}

.add1 {
    width: 97px;
    height: 126px;
    border-radius: 10px;
    box-shadow: 0px 0px 8px #f1f1f5;
    background-size: 20%;
    background-color: #ffffff;
    position: relative;
    margin: 0px 5px;

    .imgs {
        height: 85%;
        width: 100%;
    }

    .titles22 {
        width: 90%;
        height: 12px;
        padding-left: 5px;
        padding-bottom: 5px;
        line-height: 12px;
        overflow: hidden; // 溢出部分隐藏 
        white-space: nowrap; // 文字不换行
        text-overflow: ellipsis; // 显示省略号
        position: absolute;
        bottom: 0;
        left: 0;
        font-size: 10px;
    }

    .con{
        display: block;
        width: 20px;
        height: 20px;
        background: url(../assets/img/error.png) no-repeat center center;
        background-size: 20px 20px;
        position: absolute;
        top: 0;
        right: 0;
    }
}
</style>